#include<iostream>
#include<unistd.h>
#include<pthread.h>
using namespace std;

int g_val=100;

//可以被多个执行流同时启动,show函数被重入了
void show(const string &name)
{
    cout<<name<<"say#"<<"hello thread"<<endl;
}

//new thread
void *threadRoutine(void *args)
{
    while(true)
    {
        cout<<"main thread,pid:"<<getpid()<<",g_val:"<<g_val<<",&g_val"<<&g_val<<endl;
        cout<<"new thread,pid:"<<getpid()<<endl;
        show("[new thread]");
        sleep(2);
    }
}

int main()
{
    pthread_t tid;
    pthread_create(&tid,nullptr,threadRoutine,nullptr);//不是系统调用

    while(true)
    {
        cout<<"main thread,pid:"<<getpid()<<",g_val:"<<g_val<<",&g_val"<<&g_val<<endl;
        show("[main thread]");
        sleep(1);
        g_val++;
    }

    //void x;
    //cout<<"point size:"<<sizeof(void*)<<endl;
    //cout<<"point size:"<<sizeof(void)<<endl;
    return 0;
}